package com.example.littleSpider.myapplication.fragment;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.example.littleSpider.myapplication.R;
import com.example.littleSpider.myapplication.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by aduser on 2017/12/6.
 */

public class VideoFragment extends BaseFragment {

//    @BindView(R.id.text_view)
//    TextView mText;
    @BindView(R.id.tablayout)
    TabLayout tabLayout;
    @BindView(R.id.view_page)
    ViewPager mViewPager;

    FragmentManager manager;

    List<Fragment> fragmentList = new ArrayList<>();
    FragmentHotVideo fragmentOne = new FragmentHotVideo();
    FragmentHotVideo fragmentTwo = new FragmentHotVideo();

    @Override
    protected int setLayout() {
        return R.layout.fragment_video;
    }

    @Override
    protected void initView() {
//        mText.setText("窈窕淑女");
        fragmentList.add(fragmentOne);
        fragmentList.add(fragmentTwo);
        manager = getActivity().getSupportFragmentManager();
//        tabLayout.setTabTextColors();
        tabLayout.setupWithViewPager(mViewPager);
        mViewPager.setAdapter(new MyPageAdapter(manager));
    }

    @Override
    protected void initData() {

    }

    class MyAdapter extends PagerAdapter{

        @Override
        public int getCount() {
            return 4;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {

            return false;
        }


    }
    class MyPageAdapter extends FragmentPagerAdapter {

        FragmentManager manager;

        public MyPageAdapter(FragmentManager fm) {
            super(fm);
            manager = fm;
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            if (position == 0){
                return "最新";
            }else {
                return "最热";
            }
        }
    }

}
